package com.pangsir.bookstore.controller;

import com.pangsir.bookstore.pojo.Order;
import com.pangsir.bookstore.pojo.User;
import com.pangsir.bookstore.service.OrderService;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.UUID;

public class OrderController {

    private OrderService orderService;

    public String checkout(HttpSession session){
        Order order = new Order();
        Date now = new Date();
        int year = now.getYear();
        int month = now.getMonth();
        int day = now.getDate();
        int hours = now.getHours();
        int minutes = now.getMinutes();
        int seconds = now.getSeconds();
        order.setOrderNo(UUID.randomUUID().toString() +"_" +year+month + day
                + hours+minutes+seconds);
        order.setOrderDate(now);
        User currUser = (User) session.getAttribute("currUser");
        order.setOrderUser(currUser);
        order.setOrderMoney(currUser.getCart().getTotalMoney());
        order.setOrderStatus(0);
        orderService.addOrder(order);
        session.setAttribute("order",order);
        return "cart/checkout";
    }
}
